layui.define(['jquery', 'laytpl', "c4uindex"], function(exports) {
	var $ = layui.jquery;
	var laytpl = layui.laytpl;
	var c4uIndex = layui.c4uindex;

	var c4uMenuFunc = {
		newFile: function(obj, $scope) {
			layui.use('layer', function() {
				layui.layer.open({
					type: 2,
					resize: false,
					area: ['500px', '300px'],
					content: ['html/menu/newFile.html', 'no'],
					btn: ["确定", "取消"],
					yes: function(index, layero) {
						var body = layer.getChildFrame('body', index);
						var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
						var data = iframeWin.getForm();
						$.Project.addFile($.Project.File("", data.Name, data.Group, data.Category), function(fileRtn) {
							var tpl = $("#filetpl").html();
							$("#" + fileRtn.Category).append(laytpl(tpl).render({
								files: [fileRtn],
								type: fileRtn.Category
							}));
							$("#file_" + fileRtn.ID).click(function() {
								var id = $(this).attr("id");
								var name = $(this).text();
								var type = $(this).attr("data-type");
								c4uIndex.addTab(id, name, "url:html/" + type + "/index.html?id=" + id);
							});
							layui.layer.closeAll();
						});
					}
				});
			});
		},
		newDir: function(obj) {
			console.log(obj.id)
		},
		exit: function(obj) {
			$.Common.Dialog.confirm("确定退出编辑器？", function() {
				window.opener = null;
				window.open('', '_self').close();
			});
		},
		find: function(obj) {
			console.log(obj.id)
		},
		replace: function(obj) {
			console.log(obj.id)
		},
		build: function(obj) {
			$.Build["build"]();
		},
		rebuild: function(obj) {
			$.Build["rebuild"]();
		},
		clean: function(obj) {
			$.Build["clean"]();
		},
		run: function(obj) {
			$.Run["run"]();
		},
		debug: function(obj) {
			$.Run["debug"]();
		},
		stop: function(obj) {
			$.Run["stop"]();
		},
		web: function(obj) {
			window.opener = null;
			window.open('http://www.code4u.tech', '_blank');
		},
		about: function(obj) {
			$.Common.Dialog.info("<h3 style='text-align:center'>Code4U</h3><p style='text-align:center'>©2018 Shooter. 版权所有. </p>");
		}
	};
	exports('menufunc', c4uMenuFunc);
});